/*
 * Copyright (c) 2016, www.zm0618.com All Rights Reserved..
 */

package com.ibetter.mr.parse.voteup;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created by zhaojun on 2016/12/07.
 */
public class UserVoteMedicMapper extends Mapper<LongWritable,Text,LongWritable,LongWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if (value!=null){
            String valStr=value.toString();
            if(StringUtils.isNotBlank(valStr)){
                String[] voteUpField = valStr.split(",");
                if (ArrayUtils.isNotEmpty(voteUpField)){
                    String userIdStr=voteUpField[1];
                    String medicIdStr=voteUpField[2];
                    LongWritable userIdLong=new LongWritable(Long.parseLong(StringUtils.trim(userIdStr)));
                    LongWritable medicIdLong=new LongWritable(Long.parseLong(StringUtils.trim(medicIdStr)));
                    context.write(userIdLong,medicIdLong);
                }
            }
        }
    }
}
